#!/bin/sh
# - runtime
# - seed

. $LKP_SRC/lib/env.sh
. $LKP_SRC/lib/reproduce-log.sh

## A Linux System call fuzz tester

[ -n "$seed" ] || {
	echo Seeding trinity based on $kconfig
	if has_cmd cksum; then
		seed=$(echo $kconfig | cksum)
		seed=${seed%% *}
	else
		seed=$(echo $kconfig | md5sum | cut -c1-5)
		seed=$(( 0x$seed ))
	fi
}

# suppress "Killed" message to stderr
set +m

cmd="trinity -q -q -l off -s $seed -x get_robust_list -x remap_file_pages -N 999999999"

has_cmd trinity || {
	 [ -x /lkp/benchmarks/trinity/bin/trinity ] && ln -sf /lkp/benchmarks/trinity/bin/trinity /bin/trinity
}

has_cmd trinity || {
	echo "trinity is not installed" >&2
	exit 1
}

cd /tmp
if chroot --help 2>&1 | grep -q -- --userspec; then
	groupadd nogroup 2>&1 # for clearlinux
	log_cmd chroot --userspec nobody:nogroup / $cmd 2>&1 &
else
	log_cmd $cmd -X 2>&1 &
fi

pid=$!
sleep $runtime

kill -9 $pid
